Skip to content

Allow stock transfer to merge into existing stock (optional) #6951#12022

Open
neilbeukes wants to merge 12 commits into
inventree:masterfrom
neilbeukes:merge-transfer
Open

Allow stock transfer to merge into existing stock (optional) #6951#12022
neilbeukes wants to merge 12 commits into
inventree:masterfrom
neilbeukes:merge-transfer

Conversation

@neilbeukes
Copy link
Copy Markdown
Contributor

@neilbeukes neilbeukes commented May 27, 2026

As requested in #6951, I am providing an option when transferring stock between locations, to optionally merge into the first available stock of the same type (of part).

New parts added.

  • Option on transfer modal to enable merge after transfer
  • Global settings line to set the default state of the option on the modal
  • Tracking entries to signal transfer of stock
  • Tests for new transfer-merge logic.

This is will change existing behavior as follows.

If merge is toggled

  • Look for first matching stock item in destination location.
    • If matching stock found, perform a standard merge between transferred stock and existing matched stock.
    • if no matching stock found then follow existing transfer logic.
  • History of destination stock remains the same, and get another tracking event signalling stock transferred and from where.

If merged is not toggled

  • Existing behaviour stays intact i.e transferred stock will become its "own" stock in the destination location.

Some images:

Global settings
image

Modal with merge enabled on transfer
image

Middle event is an example of a merged transfer
image

@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 3cbf2f4
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a22ca4dc4b39c0008415b47

@neilbeukes
Copy link
Copy Markdown
Contributor Author

Oh I see some builds failing, ill take a look at those. I'm assuming I need to also update docs with added functionality.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 91.46341% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.43%. Comparing base (d2bec03) to head (19db981).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12022   +/-   ##
=======================================
  Coverage   91.42%   91.43%           
=======================================
  Files         974      974           
  Lines       51915    51995   +80     
=======================================
+ Hits        47465    47541   +76     
- Misses       4450     4454    +4     
Flag Coverage Δ
backend 90.44% <91.46%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.75% <91.46%> (-0.01%) ⬇️
Backend General 93.36% <ø> (ø)
Frontend ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matmair
Copy link
Copy Markdown
Member

matmair commented May 27, 2026

  1. you need to bump the version in api_version.py and add a entry in the docstring below
  2. you need to add a doc section for STOCK_MERGE_ON_TRANSFER - see global.md

Comment thread src/backend/InvenTree/stock/models.py Outdated
Comment on lines +2310 to +2315
if other.location:
location_note = _('Transferred from %(location)s') % {
'location': other.location.pathstring
}

notes = f'{notes}\n{location_note}' if notes else location_note
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it will be very hard to trace back and also like a data loss

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any newlines are stripped out from char fields too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You guys are right, thanks for pointing it out. Stripping the existing tracking event and replacing it with a lesser detailed event makes no sense. Im mostly reusing the existing event now.
image

@SchrodingersGat
Copy link
Copy Markdown
Member

@neilbeukes looking good! Only issue is that the code is not meeting style guidelines:

image

If you run pre-commit install in your local repo, it will automatically format the code for you on each git commit.

@SchrodingersGat SchrodingersGat added this to the 1.4.0 milestone Jun 2, 2026
@neilbeukes
Copy link
Copy Markdown
Contributor Author

@neilbeukes looking good! Only issue is that the code is not meeting style guidelines:
image

If you run pre-commit install in your local repo, it will automatically format the code for you on each git commit.

Hi @SchrodingersGat. I would expect this to automatically run on commit as per the docs.

Is there a way I can run that manually? I dont see any scripts in package.json or as a invoke-able task.

Thanks,

@SchrodingersGat
Copy link
Copy Markdown
Member

Hi @SchrodingersGat. I would expect this to automatically run on commit as per the docs.

It will, after you install the pre-commit hooks: https://docs.inventree.org/en/stable/develop/contributing/#setup-devtools

After this, any git commit will automatically format the code.

Is there a way I can run that manually? I dont see any scripts in package.json or as a invoke-able task.

Yes, you can replicate what the pre commit file is doing

@neilbeukes
Copy link
Copy Markdown
Contributor Author

neilbeukes commented Jun 5, 2026

Hi @SchrodingersGat. I would expect this to automatically run on commit as per the docs.

It will, after you install the pre-commit hooks: https://docs.inventree.org/en/stable/develop/contributing/#setup-devtools

After this, any git commit will automatically format the code.

Is there a way I can run that manually? I dont see any scripts in package.json or as a invoke-able task.

Yes, you can replicate what the pre commit file is doing

I see,

I did setup dev tools and have had all the pre-checks running everytime I commit but it doesnt seem to pick up those formatting.

image

Ill look into the more this weekend, maybe I can see why its not running as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants